package com.example.ycymyapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class ZhuCeActivity extends AppCompatActivity {
    EditText et_user,et_pwd,et_repeat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu_ce);

        et_user=findViewById(R.id.et_user);
        et_pwd=findViewById(R.id.et_pwd);
        et_repeat=findViewById(R.id.et_repeat);
    }

    public void save(View view){
        String user=et_user.getText().toString().trim();
        if (user.equals(null)||user.equals("")){
            Toast.makeText(this,"用户必须输入！",Toast.LENGTH_SHORT).show();
            return;
        }
        String pwd=et_pwd.getText().toString().trim();
        if (pwd.equals(null)||pwd.equals("")){
            Toast.makeText(this,"密码必须输入！",Toast.LENGTH_SHORT).show();
            return;
        }
        String repeat=et_repeat.getText().toString().trim();
        if (repeat.equals(null)||repeat.equals("")){
            Toast.makeText(this,"确认密码必须输入！",Toast.LENGTH_SHORT).show();
            return;
        }
        if (pwd.equals(repeat)){

            SharedPreferences userSetting=getSharedPreferences("user",MODE_PRIVATE);
            SharedPreferences.Editor editor=userSetting.edit();
            editor.putString("id",user);
            editor.putString("pwd",pwd);
            editor.apply();
            Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
            Intent intent=new Intent();
            intent.putExtra("id",user);
            intent.putExtra("pwd",pwd);
            setResult(1004,intent);
            finish();
        }else {
            Toast.makeText(this,"两次输入的密码必须输入！",Toast.LENGTH_SHORT).show();
            return;
        }
    }
    public void reset(View view){
        et_user.setText("");
        et_pwd.setText("");
        et_repeat.setText("");
    }
}
